import Vue from "vue";
import VueRouter from "vue-router";

Vue.use(VueRouter);

const originalPush = VueRouter.prototype.push;

VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch((err) => err);
};

const routes = [
  {
    path: "/",
    //重定向到/login
    redirect: "/login",
  },

  // 配置登录组件路由
  {
    path: "/login",
    name: "Login",
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () =>
      import(/* webpackChunkName: "about" */ "../views/Login.vue"),
  },
  {
    path: "/main",
    name: "Main",
    component: () => import("../views/Main.vue"),
    meta: {
      requireAuth: true,
    },
    children: [
      
      /*
        课程列表路由----------------------------------------------------
      */
      {
        path: "/list",
        name: "Course",
        component: () => import("../views/course/CourseList.vue"),
        meta: {
          requireAuth: true,
        },
      },
      
      /*
        个人信息修改路由----------------------------------------------------
      */
      {
        path: "/user/changeAvatar",
        name: "ChangeAvatar",
        component: () => import("../views/ChangeAvatar.vue"),
        meta: {
          requireAuth: true,
        },
      },

      /*
        课程内容路由----------------------------------------------------
      */
      {
        path: "/coursedetail/:courseId",
        name: "CourseDetail",
        component: () => import("../views/course/CourseDetail.vue"),
        meta: {
          requireAuth: true,
        },
        children: [

          /*
            班级路由----------------------------------------------------
          */
          {
            path: "/clazz",
            name: "CourseDetail",
            component: () => import("../views/course/detail/clazz/Clazz.vue"),
            meta: {
              requireAuth: true,
            },
          },
          {
            path: "/clazz_student_list",
            name: "CourseDetail",
            component: () => import("../views/course/detail/clazz/ClazzStudentList.vue"),
            meta: {
              requireAuth: true,
            },
          },

          /*
            课件路由----------------------------------------------------
          */
          {
            path: "/chapter",
            name: "CourseDetail",
            component: () =>
              import("../views/course/detail/chapter/Chapter.vue"),
              meta: {
                requireAuth: true,
              },
          },
          {
            path: "/chapter_input",
            name: "CourseDetail",
            component: () =>
              import("../views/course/detail/chapter/ChapterInput.vue"),
              meta: {
                requireAuth: true,
              },
          },
          {
            path: "/chapter_update",
            name: "CourseDetail",
            component: () =>
              import("../views/course/detail/chapter/ChapterUpdate.vue"),
              meta: {
                requireAuth: true,
              },
          },
          {
            path: "/chapter_explore",
            name: "CourseDetail",
            component: () =>
              import("../views/course/detail/chapter/ChapterExplore.vue"),
              meta: {
                requireAuth: true,
              },
          },

          /*
            作业路由----------------------------------------------------
          */
          {
            path: "/task",
            name: "CourseDetail",
            component: () =>
              import("../views/course/detail/task/Task.vue"),
              meta: {
                requireAuth: true,
              },
          },
          {
            path: "/task_input",
            name: "CourseDetail",
            component: () => import("../views/course/detail/task/TaskInput.vue"),
            meta: {
              requireAuth: true,
            },
          },
          {
            path: "/task_update",
            name: "CourseDetail",
            component: () => import("../views/course/detail/task/TaskUpdate.vue"),
            meta: {
              requireAuth: true,
            },
          },
          {
            path: "/task_explorer",
            name: "CourseDetail",
            component: () => import("../views/course/detail/task/TaskExplorer.vue"),
            meta: {
              requireAuth: true,
            },
          },
          {
            path: "/task_write",
            name: "CourseDetail",
            component: () => import("../views/course/detail/task/TaskWrite.vue"),
            meta: {
              requireAuth: true,
            },
          },
          {
            path: "/task_post_list",
            name: "CourseDetail",
            component: () => import("../views/course/detail/task/TaskPostList.vue"),
            meta: {
              requireAuth: true,
            },
          },

          /*
            资料路由----------------------------------------------------
          */
          {
            path: "/material",
            name: "CourseDetail",
            component: () => import("../views/course/detail/material/File.vue"),
            meta: {
              requireAuth: true,
            },
          }
        ],
      },
    ],
  },
  {
    path:'*',
    component: () => import("../views/NotFound.vue"),
    meta: {
      requireAuth: true,
    },
  }
];

const router = new VueRouter({
  routes,
});

export default router;
